<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=basePath %>js/jquery-1.9.0.js"></script>
<script type="text/javascript">
	$(function(){
		//文本框失去焦点时执行
		$("#mobile").blur(function(){
			 //需要校验的手机号码
			var mobile_ = $.trim($("#mobile").val());
			if(!isNotNull(mobile_)){
				alert("手机号码不能为空!");
				return ;
			}
			
			if(isNotDuplication()){
				alert("恭喜你该手机号码未被使用,可以注册!")
				
			}else{
				
				alert("抱歉,该号码已经被占用,请更换!");
			}
			
		
			
		
			
		})
	});
	
	//判断是否为空
	function isNotNull(value){
		
		if($.trim(value)==""){
			return false;
		}
		return true;
	}
	
	//校验手机号码是否重复
	function  isNotDuplication(){
		//校验类型
		var type_ = "mobile";
		//需要校验的手机号码
		var mobile_ = $.trim($("#mobile").val());
		//true:不重复, false:重复
		var notDup = false;
	
		$.ajax({
			type : "POST",
			url : "isNotDuplication",
			data :  {"type":type_,"value":mobile_},
			//同步
		    async: false,
			success : function(result) {
				if(result.success){
					//不重复
					notDup = true;
				}else{
					//重复
					notDup = false;
				}
			},
			error : function(error) {
				//alert("error")
				//重复
				notDup = false;
			}
		});
		if(notDup){
			return true;
		}else{
			return false;
		}
	}

	//注册
	function regist() {
		//需要校验的手机号码
		var mobile_ = $.trim($("#mobile").val());
		//手机验证码
		var securityCode_ = $.trim($("#securityCode").val());
		//密码
		var password_ = $.trim($("#password").val());
		//密码确认
		var password2_ = $.trim($("#password2").val());
		
		//手机和密码以及手机验证码不能为空
		if(!isNotNull(mobile_)||!isNotNull(password_)||!isNotNull(securityCode_)){
			alert("手机号码和密码以及手机验证码不能为空!");
			return;
		}
		
		//##########################校验手机号是否符合规则
		//TODO
		
		
		//判断两次密码是否一致
		if(password_!=password2_){
			alert("两次密码输入不一致");
			return;
		}
		
		if(!isNotDuplication()){
			alert("抱歉,该号码已经被占用,请更换!");
			return;
		}
		
		$.ajax({
			type : "POST",
			url : "regist",
			data :  {"mobile":mobile_,"password":password_,"securityCode":securityCode_},
			success : function(result) {
				if(result.success){
					alert("注册成功!")
				}else{
					alert("注册失败!")
				}
			},
			error : function(error) {
				alert("error")
			}

		});
	}
</script>
<title>regist</title>
</head>
<body>
	
		手机:<input type="text" id="mobile" name="mobile" placeholder="请输入手机号码" />
		<button id="codebtn" name="codebtn" >点击获取验证码</button>
		
		<br/>
		手机验证码:<input type="text" id="securityCode" name="securityCode" placeholder="请输入手机验证码" />
	
		<br />
		密码:<input type="password" id="password" name="password" placeholder="请输入密码" />
		<br/>
		<td>密码确认:<input type="password" id="password2" name="password2" placeholder="请再次输入密码" />
		邀请码:<input type="text" id="registInviteCode" name="registInviteCode" placeholder="请输入邀请码" />
		<br />
		
			<button id="loginbtn" name="loginbtn" onclick="regist()">注册</button>
			<button  type="reset" id="cancelbtn" name="cancelbtn" >取消</button>
		
	
</body>
</html>